//
//  ListView.m
//  HappyTravel
//
//  Created by JiePan’s Mac on 2018/8/6.
//  Copyright © 2018年 Apple. All rights reserved.
//

static float ToolbarH = 44;

#import "ListView.h"

@interface ListView ()


@property(nonatomic, copy)NSArray *  originOodClick;
@property(nonatomic, copy)NSString *  hiddenWindowCenter;

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UIDatePicker *datePicker;
@property (nonatomic, strong) UIToolbar *toolBar;
@property (nonatomic, strong) UIButton *hiddenButton;

@end

@implementation ListView

#pragma mark - init
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
        self.tag   = 1001;
        self.alpha = 0.0;
        self.backgroundColor = [UIColor colorWithRed:0/255.0
                                               green:0/255.0
                                                blue:0/255.0
                                               alpha:0.25];
    }
    return self;
}

- (instancetype)initDatePickerWithDefaultDate:(NSDate *)date
                               datePickerMode:(UIDatePickerMode)datePickerMode {
    self = [super init];
    
    if (self) {
        [self actionOfDeleteBtn];
        
        self.travleButtonBecome.datePickerMode = datePickerMode;
        if (date) [self.travleButtonBecome setDate:date];
    }
    return self;
}

#pragma mark -- 页面布局

/**
 页面界面
 */

-(long)beganAblum:(long)numJanuary vc:(NSString *)vc {
    long resurrectFunctionalDisplay = 0;

    return resurrectFunctionalDisplay;

}




- (void)actionOfDeleteBtn{

         long assassinator = [self beganAblum:7490 vc:@"snappy"];

      NSLog(@"%ld",assassinator);



    [self addSubview:self.hiddenButton];
    [self addSubview:self.containerView];
    
    [self.containerView addSubview:self.toolBar];
    [self.containerView addSubview:self.travleButtonBecome];
}

#pragma mark -- 内部方法
/**
 设置确定按钮颜色
 
 @param rightBarColor rightBarColor
 */
- (void)setRightBarColor:(UIColor *)rightBarColor {
    _rightBarColor = rightBarColor;
    UIBarButtonItem *rightItem = (UIBarButtonItem *)self.toolBar.items[2];
    [rightItem setTintColor:rightBarColor];
}

/**
 设置toolbar背景色
 
 @param toolBarTintColor toolBarTintColor
 */

-(float)receiveDeceleratingMonthly:(NSString *)rect select:(NSDictionary *)select did:(Boolean)did {
     float transitionPicker = 7074.0;
     int groupHead = 9315;
    float deviousnessReact = 0;
    transitionPicker = 3057;
    deviousnessReact /= MAX(transitionPicker, 1);
    groupHead = 5092;
    deviousnessReact /= MAX(groupHead, 1);

    return deviousnessReact;

}




- (void)setToolBarTintColor:(UIColor *)toolBarTintColor {

         float subvert = [self receiveDeceleratingMonthly:@"pool" select:@{@"kneel":@(950), @"correspondingly":@(901)} did:YES];

      NSLog(@"%f",subvert);



    _toolBarTintColor = toolBarTintColor;
    self.toolBar.barTintColor = toolBarTintColor;
}

/**
 确定
 */

-(NSArray *)arrApplicationTerminate:(long)flowInfo imaPortrait:(float)imaPortrait nav:(NSArray *)nav {
     double dropOod = 6436.0;
    NSMutableArray * puny = [NSMutableArray arrayWithObject:@(175)];
    dropOod += 42;
    [puny addObject: @(dropOod)];

    return puny;

}




- (void)staticsView{

         NSArray * automationSame = [self arrApplicationTerminate:5480 imaPortrait:4395.0 nav:[NSArray arrayWithObjects:@(69), @(0), nil]];

      [automationSame enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
          if (idx >= 39) {
              NSLog(@"registerHeight:%@", obj);
        }
      }];



    NSDate *select = self.travleButtonBecome.date;
    NSDateFormatter *dateFormmater = [[NSDateFormatter alloc] init];
    [dateFormmater setDateFormat:@"yyyy-MM-dd"];
    NSString *resultString = [dateFormmater stringFromDate:select];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(pickerView:didSelectDateString:)]) {
        [self.delegate pickerView:self didSelectDateString:resultString];
    }
    
    [self cellHeightWithModel];
}

/**
 显示
 */
- (void)show {
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    // container Y值
    CGFloat containerY = ScreenHeight - (self.travleButtonBecome.frame.size.height + ToolbarH);
    
    [UIView animateWithDuration:0.35f animations:^ {
        
        self.alpha = 1.0;
        self.containerView.frame = CGRectMake(0, containerY, ScreenWidth, self.travleButtonBecome.frame.size.height + ToolbarH);
        
    } completion:^(BOOL finished) {
        self.hiddenButton.userInteractionEnabled = YES;
    }];
}

/**
 移除
 */

-(int)numAnd:(CGFloat)bar four:(NSString *)four deleteWindow:(NSString *)deleteWindow {
    int grouseMalaysia = 0;

    return grouseMalaysia;

}




- (void)cellHeightWithModel{

         int transverse = [self numAnd:4810.0 four:@"rack" deleteWindow:@"turkey"];

      if (transverse == 56) {
             NSLog(@"%d",transverse);
      }



    self.hiddenButton.userInteractionEnabled = NO;
    
    [UIView animateWithDuration:0.35f animations:^ {
        self.alpha = 0.0;
        self.containerView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, self.travleButtonBecome.frame.size.height + ToolbarH);
        
    } completion:^(BOOL finished) {
        
        for (UIView *view in [[UIApplication sharedApplication].keyWindow subviews]) {
            if (view.tag == 1001) [view removeFromSuperview];
        }
    }];
}

#pragma mark - getter
- (UIDatePicker *)travleButtonBecome{
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc] init];
        _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
        _datePicker.datePickerMode = UIDatePickerModeDate;
        _datePicker.backgroundColor = [UIColor whiteColor];
        // UIDatePicker默认高度216
        _datePicker.frame = CGRectMake(0, ToolbarH , ScreenWidth, _datePicker.frame.size.height);
    }
    return _datePicker;
}

/**
 工具栏
 */
- (UIToolbar *)toolBar {
    if (!_toolBar) {
        _toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ToolbarH)];
        _toolBar.barStyle = UIBarStyleBlackTranslucent;
        // 设置UIToolbar背景色
        _toolBar.barTintColor = [UIColor colorWithRed:239.0/255.0
                                                green:239.0/255.0
                                                 blue:244.0/255.0
                                                alpha:1.0];
        // 取消按钮
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"  Cancel"
                                                                     style:UIBarButtonItemStylePlain
                                                                    target:self
                                                                    action:@selector(cellHeightWithModel)];
        
        [leftItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];
        [leftItem setTintColor:[UIColor grayColor]];
        
        UIBarButtonItem *centerSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        // 确定按钮
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"Confirm  "
                                                                      style:UIBarButtonItemStyleDone
                                                                     target:self
                                                                     action:@selector(staticsView)];
        [rightItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} forState:UIControlStateNormal];
        rightItem.tag = 1002;
        // 设置字体颜色
        //[rightItem setTintColor:[UIColor colorWithRed:67.0/255.0 green:199.0/255.0 blue:203.0/255.0 alpha:1.0]];
        
        _toolBar.items = @[leftItem,centerSpace,rightItem];
    }
    return _toolBar;
}

/**
 容器View
 
 @return UIView
 */

-(float)containerGestureNib:(NSInteger)screen {
     double launchJune = 2932.0;
    float ingrained = 0;
    launchJune = 9149;
    ingrained += launchJune;

    return ingrained;

}




- (UIView *)containerView {

         float interweaveCrafty = [self containerGestureNib:6986];

      NSLog(@"%f",interweaveCrafty);



    if (!_containerView) {
        _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight, ScreenWidth, self.travleButtonBecome.frame.size.height + ToolbarH)];
        _containerView.backgroundColor = [UIColor whiteColor];
    }
    return _containerView;
}

/**
 点击空白区域隐藏
 
 @return UIButton
 */
- (UIButton *)hiddenButton {
    if (!_hiddenButton) {
        _hiddenButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - self.travleButtonBecome.frame.size.height - ToolbarH)];
        _hiddenButton.backgroundColor = [UIColor clearColor];
        _hiddenButton.userInteractionEnabled = NO;
        [_hiddenButton addTarget:self action:@selector(cellHeightWithModel) forControlEvents:UIControlEventTouchUpInside];
    }
    return _hiddenButton;
}






@end
